package 装饰模式.计算器实例;


/**
 * @author zyl
 * @Description
 * @since 2023/12/27 17:44
 */

public class OperationContext {
    Operation operation = null;
    public OperationContext(String operator){
        switch (operator){
            case "+":
                operation = new Add();
                break;
            case "-":
                operation = new Sub();
                break;
            case "*":
                operation = new Mul();
                break;
            case "/":
                operation = new Div();
                break;
            case "/+":
                Add add = new Add();
                Div div = new Div();
                div.decorate(add);
                operation = div;
                break;
        }
    }
    protected Double getResult(double numberA, double numberB){
        return this.operation.getResult(numberA,numberB);
    }
}
